package com.GDOU.service.serviceImp;

import com.GDOU.controller.activity.Code;
import com.GDOU.bean.activity.dao.ActivityDao;
import com.GDOU.bean.activity.Activity;
import com.GDOU.exception.BusinessException;
import com.GDOU.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Resource
    private ActivityDao activityDao;

    public boolean save(Activity activity) {
        return activityDao.save(activity) > 0;
    }

    public boolean update(Activity activity) {
        return activityDao.update(activity) > 0;
    }

    public boolean delete(Integer id) {
        return activityDao.delete(id) > 0;
    }

    public Activity getById(Integer id) {
        if(id == 1){
            throw new BusinessException(Code.BUSINESS_ERR,"错误！");
        }
//        //将可能出现的异常进行包装，转换成自定义异常
//        try{
//            int i = 1/0;
//        }catch (Exception e){
//            throw new SystemException(Code.SYSTEM_TIMEOUT_ERR,"服务器访问超时，请重试!",e);
//        }
        return activityDao.getById(id);
    }

    public List<Activity> getAll() {
        return activityDao.getAll();
    }
}
